<?php

// 公共助手函数

if (!function_exists('__')) {

    /**
     * 获取语言变量值
     * @param string $name 语言变量名
     * @param array  $vars 动态变量值
     * @param string $lang 语言
     * @return mixed
     */
    function __($name, $vars = [], $lang = '')
    {
        if (is_numeric($name) || !$name) {
            return $name;
        }
        if (!is_array($vars)) {
            $vars = func_get_args();
            array_shift($vars);
            $lang = '';
        }
        return \think\facade\Lang::get($name, $vars, $lang);
    }
}

if (!function_exists('format_bytes')) {

    /**
     * 将字节转换为可读文本
     * @param int    $size      大小
     * @param string $delimiter 分隔符
     * @return string
     */
    function format_bytes($size, $delimiter = '')
    {
        $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
        for ($i = 0; $size >= 1024 && $i < 6; $i++) {
            $size /= 1024;
        }
        return round($size, 2) . $delimiter . $units[$i];
    }
}

if (!function_exists('datetime')) {

    /**
     * 将时间戳转换为日期时间
     * @param int    $time   时间戳
     * @param string $format 日期时间格式
     * @return string
     */
    function datetime($time, $format = 'Y-m-d H:i:s')
    {
        $time = is_numeric($time) ? $time : strtotime($time);
        return date($format, $time);
    }
}

if (!function_exists('human_date')) {

    /**
     * 获取语义化时间
     * @param int $time  时间
     * @param int $local 本地时间
     * @return string
     */
    function human_date($time, $local = null)
    {
        return \fast\Date::human($time, $local);
    }
}

if (!function_exists('cdnurl')) {

    /**
     * 获取上传资源的CDN的地址
     * @param string  $url    资源相对地址
     * @param boolean $domain 是否显示域名 或者直接传入域名
     * @return string
     */
    function cdnurl($url, $domain = false)
    {
        $regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i";
        $url = preg_match($regex, $url) ? $url : \think\facade\Config::get('upload.cdnurl') . $url;
        if ($domain && !preg_match($regex, $url)) {
            $domain = is_bool($domain) ? request()->domain() : $domain;
            $url = $domain . $url;
        }
        return $url;
    }
}

if (!function_exists('is_really_writable')) {

    /**
     * 判断文件或文件夹是否可写
     * @param    string $file 文件或目录
     * @return    bool
     */
    function is_really_writable($file)
    {
        if (DIRECTORY_SEPARATOR === '/') {
            return is_writable($file);
        }
        if (is_dir($file)) {
            $file = rtrim($file, '/') . '/' . md5(mt_rand());
            if (($fp = @fopen($file, 'ab')) === false) {
                return false;
            }
            fclose($fp);
            @chmod($file, 0777);
            @unlink($file);
            return true;
        } elseif (!is_file($file) or ($fp = @fopen($file, 'ab')) === false) {
            return false;
        }
        fclose($fp);
        return true;
    }
}

if (!function_exists('rmdirs')) {

    /**
     * 删除文件夹
     * @param string $dirname  目录
     * @param bool   $withself 是否删除自身
     * @return boolean
     */
    function rmdirs($dirname, $withself = true)
    {
        if (!is_dir($dirname)) {
            return false;
        }
        $files = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dirname, RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $fileinfo) {
            $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
            $todo($fileinfo->getRealPath());
        }
        if ($withself) {
            @rmdir($dirname);
        }
        return true;
    }
}

if (!function_exists('copydirs')) {

    /**
     * 复制文件夹
     * @param string $source 源文件夹
     * @param string $dest   目标文件夹
     */
    function copydirs($source, $dest)
    {
        if (!is_dir($dest)) {
            mkdir($dest, 0755, true);
        }
        foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
            if ($item->isDir()) {
                $sontDir = $dest . DS . $iterator->getSubPathName();
                if (!is_dir($sontDir)) {
                    mkdir($sontDir, 0755, true);
                }
            } else {
                copy($item, $dest . DS . $iterator->getSubPathName());
            }
        }
    }
}

if (!function_exists('mb_ucfirst')) {
    function mb_ucfirst($string)
    {
        return mb_strtoupper(mb_substr($string, 0, 1)) . mb_strtolower(mb_substr($string, 1));
    }
}

if (!function_exists('addtion')) {

    /**
     * 附加关联字段数据
     * @param array $items  数据列表
     * @param mixed $fields 渲染的来源字段
     * @return array
     */
    function addtion($items, $fields)
    {
        if (!$items || !$fields) {
            return $items;
        }
        $fieldsArr = [];
        if (!is_array($fields)) {
            $arr = explode(',', $fields);
            foreach ($arr as $k => $v) {
                $fieldsArr[$v] = ['field' => $v];
            }
        } else {
            foreach ($fields as $k => $v) {
                if (is_array($v)) {
                    $v['field'] = isset($v['field']) ? $v['field'] : $k;
                } else {
                    $v = ['field' => $v];
                }
                $fieldsArr[$v['field']] = $v;
            }
        }
        foreach ($fieldsArr as $k => &$v) {
            $v = is_array($v) ? $v : ['field' => $v];
            $v['display'] = isset($v['display']) ? $v['display'] : str_replace(['_ids', '_id'], ['_names', '_name'], $v['field']);
            $v['primary'] = isset($v['primary']) ? $v['primary'] : '';
            $v['column'] = isset($v['column']) ? $v['column'] : 'name';
            $v['model'] = isset($v['model']) ? $v['model'] : '';
            $v['table'] = isset($v['table']) ? $v['table'] : '';
            $v['name'] = isset($v['name']) ? $v['name'] : str_replace(['_ids', '_id'], '', $v['field']);
        }
        unset($v);
        $ids = [];
        $fields = array_keys($fieldsArr);
        foreach ($items as $k => $v) {
            foreach ($fields as $m => $n) {
                if (isset($v[$n])) {
                    $ids[$n] = array_merge(isset($ids[$n]) && is_array($ids[$n]) ? $ids[$n] : [], explode(',', $v[$n]));
                }
            }
        }
        $result = [];
        foreach ($fieldsArr as $k => $v) {
            if ($v['model']) {
                $model = new $v['model'];
            } else {
                $model = $v['name'] ? \think\Db::name($v['name']) : \think\Db::table($v['table']);
            }
            $primary = $v['primary'] ? $v['primary'] : $model->getPk();
            $result[$v['field']] = $model->where($primary, 'in', $ids[$v['field']])->column("{$primary},{$v['column']}");
        }

        foreach ($items as $k => &$v) {
            foreach ($fields as $m => $n) {
                if (isset($v[$n])) {
                    $curr = array_flip(explode(',', $v[$n]));

                    $v[$fieldsArr[$n]['display']] = implode(',', array_intersect_key($result[$n], $curr));
                }
            }
        }
        return $items;
    }
}

if (!function_exists('var_export_short')) {

    /**
     * 返回打印数组结构
     * @param string $var    数组
     * @param string $indent 缩进字符
     * @return string
     */
    function var_export_short($var, $indent = "")
    {
        switch (gettype($var)) {
            case "string":
                return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"';
            case "array":
                $indexed = array_keys($var) === range(0, count($var) - 1);
                $r = [];
                foreach ($var as $key => $value) {
                    $r[] = "$indent    "
                    . ($indexed ? "" : var_export_short($key) . " => ")
                    . var_export_short($value, "$indent    ");
                }
                return "[\n" . implode(",\n", $r) . "\n" . $indent . "]";
            case "boolean":
                return $var ? "TRUE" : "FALSE";
            default:
                return var_export($var, true);
        }
    }
}

if (!function_exists('letter_avatar')) {
    /**
     * 首字母头像
     * @param $text
     * @return string
     */
    function letter_avatar($text)
    {
        $total = unpack('L', hash('adler32', $text, true))[1];
        $hue = $total % 360;
        list($r, $g, $b) = hsv2rgb($hue / 360, 0.3, 0.9);

        $bg = "rgb({$r},{$g},{$b})";
        $color = "#ffffff";
        $first = mb_strtoupper(mb_substr($text, 0, 1));
        $src = base64_encode('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100" width="100"><rect fill="' . $bg . '" x="0" y="0" width="100" height="100"></rect><text x="50" y="50" font-size="50" text-copy="fast" fill="' . $color . '" text-anchor="middle" text-rights="admin" alignment-baseline="central">' . $first . '</text></svg>');
        $value = 'data:image/svg+xml;base64,' . $src;
        return $value;
    }
}

if (!function_exists('hsv2rgb')) {
    function hsv2rgb($h, $s, $v)
    {
        $r = $g = $b = 0;

        $i = floor($h * 6);
        $f = $h * 6 - $i;
        $p = $v * (1 - $s);
        $q = $v * (1 - $f * $s);
        $t = $v * (1 - (1 - $f) * $s);

        switch ($i % 6) {
            case 0:
                $r = $v;
                $g = $t;
                $b = $p;
                break;
            case 1:
                $r = $q;
                $g = $v;
                $b = $p;
                break;
            case 2:
                $r = $p;
                $g = $v;
                $b = $t;
                break;
            case 3:
                $r = $p;
                $g = $q;
                $b = $v;
                break;
            case 4:
                $r = $t;
                $g = $p;
                $b = $v;
                break;
            case 5:
                $r = $v;
                $g = $p;
                $b = $q;
                break;
        }

        return [
            floor($r * 255),
            floor($g * 255),
            floor($b * 255),
        ];
    }
}
/**
 * 生成长整型ID
 *
 * @return string
 */
if (!function_exists('genId')) {
    function genId()
    {

        //生成24位唯一订单号码，格式：YYYY-MMDD-HHII-SS-NNNN,NNNN-CC，其中：YYYY=年份，MM=月份，DD=日期，HH=24格式小时，II=分，SS=秒，NNNNNNNN=随机数，CC=检查码
        @date_default_timezone_set("PRC");
        //日期
        //订单号码主体（YYYYMMDDHHIISSNNNNNNNN）
        $order_id_main = date('YmdHis') . rand(10000000,99999999);
        //订单号码主体长度
        $order_id_len = strlen($order_id_main);
        $order_id_sum = 0;
        for($i=0; $i<$order_id_len; $i++){

            $order_id_sum += (int)(substr($order_id_main,$i,1));

        }

        //唯一订单号码（YYYYMMDDHHIISSNNNNNNNNCC）
        $order_id = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
        return $order_id;
    }

}

/*
 *  富文本图片增加域名
 *  $content    文本内容
 *  $suffix     域名
 * */
if (!function_exists('get_img_thumb_url')) {
    function get_img_thumb_url($content = "", $suffix = "")
    {
        $pregRule = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
        $content = preg_replace($pregRule, '<img src="' . $suffix . '${1}" style="max-width:100%">', $content);
        return $content;
    }
}

/**
 * 移除Emoji表情
 *
 * @param $nickName
 *
 * @return null|string|string
 */
if (!function_exists('removeEmoji')) {
    function removeEmoji($nickName)
    {
        $nickName = preg_replace_callback('/./u',
            function (array $match) {
                return strlen($match[0]) >= 4 ? '' : $match[0];
            },
            $nickName
        );
        return $nickName;
    }
}

if (!function_exists('TD')) {
//调试输出
    function TD()
    {
        @header('Content-type: text/html; charset=utf-8');
        $args = func_get_args();  //获取多个参数
        if (count($args) < 1) {
            echo "<font color='red'>必须为p()函数提供参数!</font><br>";
            return;
        }
        echo '<div style="width:100%;text-align:left"><pre>';
        //多个参数循环输出
        foreach ($args as $arg) {
            if (is_array($arg)) {
                print_r($arg);
                echo '<br>';
            } elseif (is_string($arg)) {
                echo $arg . '<br>';
            } else {
                var_dump($arg);
                echo '<br>';
            }
        }
        echo '</pre></div>';
        exit();
    }
}


/**
 * 获取当前域名
 * @return https://xxxx.a.com
 */
if (!function_exists('getDomain')) {
    function getDomain($base = '')
    {

        $sysProtocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
        if ($base == 'mobile') {
            return $sysProtocal . $_SERVER['SERVER_NAME'];
        } else {
            return $sysProtocal . $_SERVER['SERVER_NAME'];
        }
    }
}

if(! function_exists('bdEncrypt'))
{
    //GCJ-02(火星，高德)坐标转换成BD-09(百度)坐标
    //@param $longitude 高德经度
    //@param $latitude 高德纬度
    function bdEncrypt($longitude,$latitude){
        $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
        $x = $longitude;
        $y = $latitude ;
        $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
        $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
        $longitude = $z * cos($theta) + 0.0065;
        $latitude = $z * sin($theta) + 0.006;
        // 保留小数点后六位
        $data['longitude'] = round($longitude, 6);
        $data['latitude'] = round($latitude, 6);
        return $data;
    }
}
if(! function_exists('gdEncrypt'))
{
    //BD-09(百度)坐标转换成GCJ-02(火星，高德)坐标
    //@param $longitude 百度经度
    //@param $latitude 百度纬度
    function gdEncrypt($longitude,$latitude){
        $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
        $x = $longitude - 0.0065;
        $y = $latitude - 0.006;
        $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
        $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
        $longitude = $z * cos($theta);
        $latitude = $z * sin($theta);
        $data['longitude'] = round($longitude, 6);
        $data['latitude'] = round($latitude, 6);
        return $data;
    }
}

//PHP获取今日、本周、本月、今年的开始日期和结束日期

if(! function_exists('beginToday')) {
    /**
     * 今天开始的Y-m-d H:i:s
     *
     * @return string
     */
    function beginToday()
    {
        return date('Y-m-d') . ' 00:00:00';
    }
}

if(! function_exists('endToday')) {
    /**
     * 今天结束的Y-m-d H:i:s
     *
     * @return string
     */
    function endToday()
    {
        return date('Y-m-d') . ' 23:59:59';
    }
}

if(! function_exists('beginWeek')) {
    /**
     * 本周的开始日期
     *
     * @param bool $His 是否展示时分秒 默认true
     *
     * @return false|string
     */
    function beginWeek($His = true)
    {
        $timestamp = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y'));
        return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
    }
}

if(! function_exists('endWeek')) {
    /**
     * 本周的结束日期
     *
     * @param bool $His 是否展示时分秒 默认true
     *
     * @return false|string
     */
    function endWeek($His = true)
    {
        $timestamp = mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y'));
        return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
    }
}

if(! function_exists('beginMonth')) {
    /**
     * 本月的开始日期
     *
     * @param bool $His 是否展示时分秒 默认true
     *
     * @return false|string
     */
    function beginMonth($His = true)
    {
        $timestamp = mktime(0, 0, 0, date('m'), 1, date('Y'));
        return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
    }
}

if(! function_exists('endMonth')) {
    /**
     * 本月的结束日期
     *
     * @param bool $His 是否展示时分秒 默认true
     *
     * @return false|string
     */
    function endMonth($His = true)
    {
        $timestamp = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
        return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
    }
}



if(! function_exists('beginYear')) {
    /**
     * 几年的开始日期
     *
     * @param bool $His 是否展示时分秒 默认true
     *
     * @return false|string
     */
    function beginYear($His = true)
    {
        $timestamp = mktime(0, 0, 0, 1, 1, date('Y'));
        return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
    }
}


if(! function_exists('endYear')) {
    /**
     * 本月的结束日期
     *
     * @param bool $His 是否展示时分秒 默认true
     *
     * @return false|string
     */
    function endYear($His = true)
    {
        $timestamp = mktime(23, 59, 59, 12, 31, date('Y'));
        return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
    }
}


if(! function_exists('strToUtf8')) {
    /*
     * 转换字符编码为utf-8
     * */
    function strToUtf8($str)
    {
        $encode = mb_detect_encoding($str, array("ASCII", 'UTF-8', "GB2312", "GBK", 'BIG5'));
        if ($encode == 'UTF-8') {
            return $str;
        } else {
            return mb_convert_encoding($str, 'UTF-8', $encode);
        }
    }
}

if(! function_exists('mb_str_split')) {
    /**
     * 分割中文字符串
     * $str 字符串
     * $count 个数
     * @param $str
     * @param $count
     * @return array
     */
    function mb_str_split($str, $count)
    {
        $leng = strlen($str) / 3;     //中文长度
        $arr = array();
        for ($i = 0; $i < $leng; $i += $count) {
            $arr[] = mb_substr($str, $i, $count);
        }
        return $arr;
    }
}
/*字符串转首字母 例如:get_letter(景大爷) = JDY   start  */
if(! function_exists('getfirstchar')) {
    //获取字的首字母
    function getfirstchar($s0)
    {
        $fchar = ord(substr($s0, 0, 1));
        if (($fchar >= ord("a") and $fchar <= ord("z")) or ($fchar >= ord("A") and $fchar <= ord("Z"))) return strtoupper(chr($fchar));
        $s = iconv("UTF-8", "GBK", $s0);
        $asc = ord($s[0]) * 256 + ord($s[1]) - 65536;
        if ($asc >= -20319 and $asc <= -20284) return "A";
        if ($asc >= -20283 and $asc <= -19776) return "B";
        if ($asc >= -19775 and $asc <= -19219) return "C";
        if ($asc >= -19218 and $asc <= -18711) return "D";
        if ($asc >= -18710 and $asc <= -18527) return "E";
        if ($asc >= -18526 and $asc <= -18240) return "F";
        if ($asc >= -18239 and $asc <= -17923) return "G";
        if ($asc >= -17922 and $asc <= -17418) return "H";
        if ($asc >= -17417 and $asc <= -16475) return "J";
        if ($asc >= -16474 and $asc <= -16213) return "K";
        if ($asc >= -16212 and $asc <= -15641) return "L";
        if ($asc >= -15640 and $asc <= -15166) return "M";
        if ($asc >= -15165 and $asc <= -14923) return "N";
        if ($asc >= -14922 and $asc <= -14915) return "O";
        if ($asc >= -14914 and $asc <= -14631) return "P";
        if ($asc >= -14630 and $asc <= -14150) return "Q";
        if ($asc >= -14149 and $asc <= -14091) return "R";
        if ($asc >= -14090 and $asc <= -13319) return "S";
        if ($asc >= -13318 and $asc <= -12839) return "T";
        if ($asc >= -12838 and $asc <= -12557) return "W";
        if ($asc >= -12556 and $asc <= -11848) return "X";
        if ($asc >= -11847 and $asc <= -11056) return "Y";
        if ($asc >= -11055 and $asc <= -10247) return "Z";
        return null;
    }
}
if(! function_exists('mb_str_split')) {
    //字符串分割单字
    function mb_str_split($string)
    {
        return preg_split('/(?<!^)(?!$)/u', $string);
    }
}
if(! function_exists('get_letter')) {
    //字符串变成首字母
    function get_letter($string)
    {
        $charlist = mb_str_split($string);
        return implode(array_map("getfirstchar", $charlist));
    }
}

/*字符串转首字母 例如:get_letter(景大爷) = JDY   end  */

if(! function_exists('getbig')) {
// 判断2个版本号的大小，并返回较大的那个，比如 1.0.9  1.1.0 ，则返回 1.1.0
// 传入由2个点分隔为3组的版本号，返回较大的那个
// 1.0.3  1.2.9 等
    function getbig($one, $two)
    {
        $onearr = explode('.', $one);
        $twoarr = explode('.', $two);
        if (intval($onearr[0]) !== intval($twoarr[0])) {
            return intval($onearr[0]) > intval($twoarr[0]) ? $one : $two;
        }

        if (intval($onearr[1]) !== intval($twoarr[1])) {
            return intval($onearr[1]) > intval($twoarr[1]) ? $one : $two;
        }
        if (intval($onearr[2]) !== intval($twoarr[2])) {
            return intval($onearr[2]) > intval($twoarr[2]) ? $one : $two;
        }
        return $one;
    }
}


if(!function_exists('encrypt')) {
    //函数encrypt($string,$operation,$key)中$string：需要加密解密的字符串；$operation：判断是加密还是解密，E表示加密，D表示解密；$key：密匙。
    function encrypt($string,$operation,$key=''){
        $key=md5($key);
        $key_length=strlen($key);
        $string=$operation=='D'?base64_decode($string):substr(md5($string.$key),0,8).$string;
        $string_length=strlen($string);
        $rndkey=$box=array();
        $result='';
        for($i=0;$i<=255;$i++){
            $rndkey[$i]=ord($key[$i%$key_length]);
            $box[$i]=$i;
        }
        for($j=$i=0;$i<256;$i++){
            $j=($j+$box[$i]+$rndkey[$i])%256;
            $tmp=$box[$i];
            $box[$i]=$box[$j];
            $box[$j]=$tmp;
        }
        for($a=$j=$i=0;$i<$string_length;$i++){
            $a=($a+1)%256;
            $j=($j+$box[$a])%256;
            $tmp=$box[$a];
            $box[$a]=$box[$j];
            $box[$j]=$tmp;
            $result.=chr(ord($string[$i])^($box[($box[$a]+$box[$j])%256]));
        }
        if($operation=='D'){
            if(substr($result,0,8)==substr(md5(substr($result,8).$key),0,8)){
                return substr($result,8);
            }else{
                return'';
            }
        }else{
            return str_replace('=','',base64_encode($result));
        }
    }

}


/**
 * 自定义日志写入
 */
if (!function_exists('customLog')) {
    /**
     * @param string $mark 日志备注
     * @param mixed $log_content &日志内容，支持数组或字符串，自动转json格式
     * @param string $folder 文件夹名称，默认为当前时间命名
     * @param string $file_name 文件名称，默认为当前时间命名
     * @throws \Exception
     */
    function customLog($mark, $log_content, $folder = '', $file_name = '')
    {
        $max_size = 30000000;
        if ($folder == "") {
            $log_filename = Env::get('runtime_path'). '/custom/' . date('Ym-d');
        } else {
            $log_filename = Env::get('runtime_path') . '/custom/' . $folder . '/' . date('Ym-d');
        }

//    if (file_exists($log_filename) && (abs(filesize($log_filename)) > $max_size)) {
//        rename($log_filename, dirname($log_filename) . DS . date('Ym-d-His') . $folder . ".log");
//    }
        !is_dir($log_filename) && mkdir($log_filename, 0755, true);

        $t = microtime(true);
        $micro = sprintf("%06d", ($t - floor($t)) * 1000000);
        $d = new \DateTime(date('Y-m-d H:i:s.' . $micro, $t));

        if (is_array($log_content)) {
            $log_content = json_encode($log_content, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }
        $file_name = $file_name ? $file_name . '.log' : date('Ymd') .
            '.log';
        file_put_contents($log_filename . '/' . $file_name, ' [' . $d->format('Y-m-d H:i:s u') . "]：" .
            $mark . "\r\n" . $log_content . "\r\n------------------------ --------------------------\r\n", FILE_APPEND);
    }
}
